package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IMaterielDao;
import com.hy.erp.inventory.dao.interfaces.IUnitConversionRateDao;
import com.hy.erp.inventory.dao.interfaces.IUnitsDao;
import com.hy.erp.inventory.extjs.gxt.ui.client.data.BaseModel;
import com.hy.erp.inventory.pojo.UnitConversionRate;
import com.hy.erp.inventory.pojo.interfaces.IMateriel;
import com.hy.erp.inventory.pojo.interfaces.IUnitConversionRate;
import com.hy.erp.inventory.pojo.interfaces.IUnits;
import com.hy.erp.inventory.service.interfaces.IUnitConversionRateService;
import com.hy.erp.inventory.vsoft.libra.enterprise.framework.persistence.entity.AbstractPersistentEntity;
/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-12；时间：上午11:39:48</li>
 * <li>类型名称：UnitConversionRateService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Name("unitConversionRateService")
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class UnitConversionRateService
										extends
										AbstractBusinessService < IUnitConversionRate >
																				implements
																				IUnitConversionRateService
{

	/**
	 * <ul>
	 * <li>开发作者：汤莉</li>
	 * <li>设计日期：2010-10-12；时间：上午11:39:39</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														1597992050214402849L ;
	/**
	 * 
	 * 构造函数
	 */
	public UnitConversionRateService()
	{
		super ( );
	}
	
	@ Override
	public boolean addUnitConversionRate (
											UnitConversionRate rate )
	{
		if(rate==null)
		{
			return true;
		}
		else
		{
			IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
			IUnitConversionRate iRate=rate;
			return dao.persist ( iRate ) ;
		}
	}

	@ Override
	public Integer removeUnitConversionRate (
												String [ ] rateIds )
	{
		if ( ( null == rateIds )
			     || ( rateIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
				return dao.remove ( rateIds );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyUnitConversionRate (
												UnitConversionRate rate )
	{
		if ( ( null == rate ) || ( null == rate.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
			IUnitConversionRate iRate=rate;
			
			if ( null == iRate )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( iRate )!=null) ;
		}
		
	}

	@ Override
	public String [ ] addUnitConversionRate (
												Object [ ] objects )
	{
		IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
		UnitConversionRate[] rates=new UnitConversionRate[objects.length];
		for ( int i =
						0 ; i < objects.length ; i ++ )
		{
			UnitConversionRate rate=( UnitConversionRate ) objects[i];
			rates[i]=rate;
		}
		return dao.persist ( rates );
	}

	@ Override
	public List < IUnitConversionRate > getAllUnitConversionRate ( )
	{
		IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
		return dao.find ( ) ;
	}

	@ Override
	public IUnitConversionRate getUnitConversionRateById (
															String id )
	{

		if (  null == id )
			{
				return null ;
			}
			else
			{
				IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
				return dao.findByIdentifier ( id );
				
			}
	
	}

	@ Override
	public IUnitConversionRate getUnitConversionRateById (
			AbstractPersistentEntity baseModel )
	{

		if (  null ==baseModel )
		{
			return null ;
		}
		else
		{
			String id =baseModel.get ( "identifier" );
		
			
			IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
			return dao.findByIdentifier ( id );
			
		}
	
	}

	@ Override
	public String [ ] modifyUnitConversionRate (
													Object [ ] objects )
	{

		if (  null == objects ) 
				{
					return null;
				}
				else
				{
					IUnitConversionRateDao dao=( IUnitConversionRateDao ) this.getDao ( IUnitConversionRate.class );
					UnitConversionRate[] types=new UnitConversionRate[objects.length];
		            for(int i=0;i<objects.length;i++)
		            {
		            	UnitConversionRate type=( UnitConversionRate ) objects[i];
		            	types[i]=type;
		            }
					
					return dao.merge ( types );
				}
	}

	

}
